package object2;

/**
 * 方法的多态
 */
public class PolyMethod {

    public static void main(String[] args) {

        //方法重载体现多态
        PolyA polyA = new PolyA();
        //这里传入不同的参数，就会调用不同的 sum 方法，就体现多态
        System.out.println(polyA.sum(10, 20));
        System.out.println(polyA.sum(10, 20, 30));

        //方法重写体现多态
        PolyB polyB = new PolyB();
        polyA.say();
        polyB.say();
    }
}

class PolyB {

    public void say() {
        System.out.println("PolyB say()方法被调用...");
    }

}

class PolyA extends PolyB {

    public int sum(int n1, int n2) {//和下面 sum 构成重载
        return n1 + n2;
    }

    public int sum(int n1, int n2, int n3) {
        return n1 + n2 + n3;
    }

    public void say() {
        System.out.println("PolyA say()方法被调用...");
    }

}